﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls;

namespace Kaesoft.Hospedaje.Admin
{
    public partial class AdministracionUsuarioView : UserControl
    {
        public AdministracionUsuarioView()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(AdministracionUsuarioView_Loaded);
            var contexto = new AdministracionUsuarioViewModel();
            this.DataContext = contexto; 
        }

        void AdministracionUsuarioView_Loaded(object sender, RoutedEventArgs e)
        {
            var vm = (AdministracionUsuarioViewModel)DataContext;
            vm.ResetPager += (s, ev) =>
            {
                if (ev.Data == "PagerUsuarios")
                    PagerUsuarios.PageIndex = 0;
            };
        }

        private void RadDataPager_PageIndexChanged(object sender, PageIndexChangedEventArgs e)
        {
            if (DataContext == null) return;
            var pager = (RadDataPager)sender;

            var vm = (AdministracionUsuarioViewModel)DataContext;
            if (pager.Name == "PagerUsuarios")
                vm.CargarUsuarios(pager.PageIndex);
        }
    }
}
